<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Balance;
use Filament\Facades\Filament;

class WithdrawController extends Controller
{
    private $amount;
    private $payment_method;
    public function __construct($amount, $payment_method)
    {
        $this->amount = $amount;
        $this->payment_method = $payment_method;
        $this->withdrawSubmit();
    }

    public function withdrawSubmit()
    {
        $balance_before = Filament::auth()->user()->balance;
        $balance_after = intval($balance_before) - intval($this->amount);
        Balance::create([
            'user_id' => Filament::auth()->user()->id,
            'type' => 'withdraw',
            'balance_before' => $balance_before,
            'balance_after' => $balance_after,
            'withdraw_method_id' => $this->payment_method,
        ]);
    }
}
